registerJQueryFunction(function(selector){
		/**
		 * Bind the event for the autodisplay action triggers.
		 */
		selector('[autodisplay_action]').each(function(){
				var autodisplayElement=$(this);
				var triggeringEvents=autodisplayElement.attr('autodisplay_events').split(' ');
				var triggeringElements=autodisplayElement.targetedElement().filter(function(){
						return !$.contains(autodisplayElement[0],this);
				});
				for(var i in triggeringEvents){
					triggeringElements.bind(triggeringEvents[i],function(){
							autodisplayElement.refreshAutodisplays();
					});
				}
				if(autodisplayElement.is('[trigger_on_load]')){
					autodisplayElement.refreshAutodisplays();
				}
		});
});

/**
 * Invoke autodisplay events triggered by this action.
 */
$.fn.refreshAutodisplays=function(){
	$(this).each(function(){
			var autodisplayElement=$(this);
			var controller_method=autodisplayElement.controllerAndMethod('autodisplay_action');
			var controller=controller_method[0];
			var method=controller_method[1];
			var checkboxesStatus=[];
			if(autodisplayElement.attr('preserve_checkboxes')){
				autodisplayElement.find(':checkbox').each(function(){
						checkboxesStatus.push({
								name:$(this).attr('name'),
								value:$(this).attr('value'),
								checked:$(this).prop('checked')
						});
				});
			}
			ajaxRequest(controller,method,autodisplayElement.collectExtraArgs(),function(data){
					autodisplayElement.htmlJQ(renderEjs(autodisplayElement.attr('ejs'),data));
					if(0<checkboxesStatus.length){
						var checkboxes=autodisplayElement.find(':checkbox');
						for(i in checkboxesStatus){
							checkboxes.filter(function(){
									return(
										$(this).attr('name')==checkboxesStatus[i].name
										&&
										$(this).attr('value')==checkboxesStatus[i].value
									);
							}).prop('checked',checkboxesStatus[i].checked);
						}
					}

					containingDialog=autodisplayElement.closest('[container=dialog]').parent();
					if(0<containingDialog.length){
						deviationFromLeft=containingDialog.position().left+containingDialog.width()-$('#mainContainer').width()+10;
						if(deviationFromLeft>0){
							containingDialog.animate({left:Math.max(0,containingDialog.position().left-deviationFromLeft)});
						}
					}
			});
	});
}
